const {
	Controller
} = require('uni-cloud-router')
const uniID = require('uni-id')

const dbHelper = require('db-helper')
module.exports = class UserController extends Controller {
	
	async removeUser() {
		let {
			ids
		} = this.ctx.data
		let transaction = await this.db.startTransaction()
		try{
			console.log('ids', ids)
			await transaction.collection("uni-id-users").where({
				_id: this.db.command.in(ids)
			}).remove()
			await transaction.collection("t3ds-account").where({
				userId: this.db.command.in(ids)
			}).remove()
			await transaction.collection("t3ds-account-log").where({
				userId: this.db.command.in(ids)
			}).remove()
			await transaction.collection("t3ds-door-open").where({
				userId: this.db.command.in(ids)
			}).remove()
			await transaction.commit()
			return {
				code: 0
			}
		}catch(e){
			await transaction.rollback()
			console.log('删除用户遇到错误', e)
			return {
				code: -1,
				msg: e.message
			}
		}
	}
	
}
